package com.zsrt.java.day20161227.lh.homework;

import java.math.BigDecimal;

import org.junit.Test;

public class Test01 {

	
	@Test
	public void mnlhongbao() throws Exception {
		hb(1,10,0.01); //钱 ，人数，最少钱
		
	}
	
	public  void hb(double total,int num,double min){

        for(int i=1;i<num;i++){

            double safe_total=(total-(num-i)*min)/(num-i);

            double money=Math.random()*(safe_total-min)+min;

            BigDecimal money_bd=new BigDecimal(money);

            money=money_bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); 

            total=total-money;

            BigDecimal total_bd=new BigDecimal(total);

            total=total_bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            System.out.println("第"+i+"个红包："+money+",余额为:"+total+"元");
        }
        System.out.println("第"+num+"个红包："+total+",余额为:0元");
    }

}
